import sys
class MinStack:
    stack = None
    min_ = sys.maxsize

    class Element:
        val = 0
        min_ = 0

        def __init__(self, val, min_):
            self.val = val
            self.min_ = min_

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []
        self.min_ = sys.maxsize

    def push(self, x):
        """
        :type x: int
        :rtype: void
        """
        if x < self.min_:
            self.min_ = x
            now = self.Element(x, x)
            self.stack.append(now)
        else:
            now = self.Element(x, self.min_)
            self.stack.append(now)

    def pop(self):
        """
        :rtype: void
        """
        self.stack.pop()
        if len(self.stack) == 0:
            self.min_ = sys.maxsize
        elif self.stack[-1].min_ != self.min_:
            self.min_ = self.stack[-1].min_


    def top(self):
        """
        :rtype: int
        """
        return self.stack[-1].val

    def getMin(self):
        """
        :rtype: int
        """
        return self.stack[-1].min_

# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()